package com.wingsboat.graphvis.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wingsboat.common.log.annotation.Log;
import com.wingsboat.common.log.enums.BusinessType;
import com.wingsboat.common.security.annotation.RequiresPermissions;
import com.wingsboat.graphvis.domain.GvNode;
import com.wingsboat.graphvis.service.IGvNodeService;
import com.wingsboat.common.core.web.controller.BaseController;
import com.wingsboat.common.core.web.domain.AjaxResult;
import com.wingsboat.common.core.utils.poi.ExcelUtil;
import com.wingsboat.common.core.web.page.TableDataInfo;

/**
 * 节点信息Controller
 * 
 * @author wangzhong
 * @date 2024-04-20
 */
@RestController
@RequestMapping("/node")
public class GvNodeController extends BaseController
{
    @Autowired
    private IGvNodeService gvNodeService;

    /**
     * 查询节点信息列表
     */
    @RequiresPermissions("graphvis:node:list")
    @GetMapping("/list")
    public TableDataInfo list(GvNode gvNode)
    {
        startPage();
        List<GvNode> list = gvNodeService.selectGvNodeList(gvNode);
        return getDataTable(list);
    }

    /**
     * 查询节点信息列表
     */
    @RequiresPermissions("graphvis:node:list")
    @GetMapping("/listAll")
    public AjaxResult listAll(GvNode gvNode)
    {
//        List<Map<String,Object>> result = new ArrayList<>();
//        for(int i=0;i<5;i++){
//            Map<String,Object> map = new HashMap<>();
//            map.put("id",String.valueOf(i));
//            map.put("type","任务");
//            map.put("label","任务"+i);
//            result.add(map);
//        }
//        return AjaxResult.success(result);
        List<GvNode> list = gvNodeService.selectGvNodeList(gvNode);
        return AjaxResult.success(list);
    }

    /**
     * 导出节点信息列表
     */
    @RequiresPermissions("graphvis:node:export")
    @Log(title = "节点信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GvNode gvNode)
    {
        List<GvNode> list = gvNodeService.selectGvNodeList(gvNode);
        ExcelUtil<GvNode> util = new ExcelUtil<GvNode>(GvNode.class);
        util.exportExcel(response, list, "节点信息数据");
    }

    /**
     * 获取节点信息详细信息
     */
    @RequiresPermissions("graphvis:node:query")
    @GetMapping(value = "/{nodeId}")
    public AjaxResult getInfo(@PathVariable("nodeId") Integer nodeId)
    {
        return success(gvNodeService.selectGvNodeByNodeId(nodeId));
    }

    /**
     * 新增节点信息
     */
    @RequiresPermissions("graphvis:node:add")
    @Log(title = "节点信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GvNode gvNode)
    {
        return toAjax(gvNodeService.insertGvNode(gvNode));
    }

    /**
     * 修改节点信息
     */
    @RequiresPermissions("graphvis:node:edit")
    @Log(title = "节点信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GvNode gvNode)
    {
        return toAjax(gvNodeService.updateGvNode(gvNode));
    }

    /**
     * 删除节点信息
     */
    @RequiresPermissions("graphvis:node:remove")
    @Log(title = "节点信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{nodeIds}")
    public AjaxResult remove(@PathVariable Integer[] nodeIds)
    {
        return toAjax(gvNodeService.deleteGvNodeByNodeIds(nodeIds));
    }
}
